home *** CD-ROM | disk | FTP | other *** search
- Path: news.nevada.edu!chancl
- From: chancl@nevada.edu (Clapton Chan)
- Newsgroups: comp.lang.c
- Subject: why get 9 strings only?
- Date: 24 Jan 1996 10:33:21 GMT
- Organization: University of Nevada System Computing Services
- Message-ID: <4e51th$4bi@news.nevada.edu>
- NNTP-Posting-Host: unauthenticated_user@pioneer.nevada.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- I can't figure out why I can only input 9 strings
- instead of 10 on the following program:
-
- **************************************************************
-
- /* Write a program that reads a number and then a list of */
- /* strings (all on separate lines), and then prints one of */
- /* the lines from the list as selected by the number. */
-
- #include <stdio.h>
-
- void main()
- {
- char str[10][80];
- int i, j;
-
- printf("Enter a number (0-9):\n");
- scanf("%d", &j);
-
- printf("Enter 10 strings:\n");
- for(i=0; i<10; i++) /* get 10 strings */
- gets(str[i]); /* but can input 9 strings */
-
- if(j>0 && j<10)
- printf("Answer: %s\n", str[j]);
- }
-
- **********************************************************
-
- I have debugged it and find the when "i" comes to
- "gets(str[i])", "i" bumps up to two before accepting
- the first input string. Why?
-
- Please email me any hint. Thanks in advance.
-
- Cheers,
- Clapton
-